var Login = function() {

    var handleLogin = function() {

        $('.login-form').validate({
            errorElement: 'span', //default input error message container
            errorClass: 'help-block font-red', // default input error message class
            focusInvalid: false, // do not focus the last invalid input
            rules: {
                loginName: {
                    required: true
                },
                password: {
                    required: true
                },
                remember: {
                    required: false
                }
            },

            messages: {
                loginName: {
                    required: "请输入用户名"
                },
                password: {
                    required: "请输入密码"
                }
            },

            // 显示或者隐藏验证信息，可以自动实现有错误信息出现时把容器属性变为显示，无错误时隐藏。
            errorContainer: ".alert-danger",

            highlight: function(element) { // hightlight error inputs
                $(element).closest('.form-group').addClass('has-error'); // set error class to the control group
            },

            errorPlacement: function(error) {
                $("#server_message").text("");
                $(".alert-danger").append( error );
            },

            submitHandler: function(form) {
                form.submit(); // form validation success, call ajax form submit
            }
        });
    };

    return {
        //main function to initiate the module
        init: function() {

            handleLogin();

            // init background slide images
            $('.login-bg').backstretch([
                "assets/pages/img/login/bg01.png",
                "assets/pages/img/login/bg02.png"
                ], {
                  fade: 1000,
                  duration: 5000
                }
            );
        }
    };
}();

jQuery(document).ready(function() {
    Login.init();
});